/*
 * *******************************************************************
 *   @项目名称: BHex Android
 *   @文件名称: OtcAdsApi.java
 *   @Date: 19-3-4 下午4:05
 *   @Author: ppzhao
 *   @Description:
 *   @Copyright（C）: 2019 BlueHelix Inc.   All rights reserved.
 *   注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的.
 *  *******************************************************************
 */

package io.bhex.sdk.otc;

import io.bhex.baselib.network.BParamsBuilder;
import io.bhex.baselib.network.HttpUtils;
import io.bhex.baselib.network.listener.SimpleResponseListener;
import io.bhex.baselib.network.params.PostParams;
import io.bhex.baselib.network.response.ResultResponse;
import io.bhex.baselib.utils.MD5Utils;
import io.bhex.sdk.OTCUrls;
import io.bhex.sdk.otc.bean.OtcAdsListResponse;
import io.bhex.sdk.otc.bean.OtcPublishAdResponse;

public class OtcAdsApi {


    /**
     * 撤广告
     * @param itemId
     * @param listener
     */
    public static void cancelAd(String itemId, SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_CANCEL)
                .addParam("itemId",itemId)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 下架广告
     * @param itemId
     * @param listener
     */
    public static void offlineAd(String itemId, SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_OFFLINE)
                .addParam("itemId",itemId)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 上架广告
     * @param itemId
     * @param listener
     */
    public static void onlineAd(String itemId, SimpleResponseListener<ResultResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_ONLINE)
                .addParam("itemId",itemId)
                .build();
        HttpUtils.getInstance().request(params,ResultResponse.class,listener);
    }

    /**
     * 广告委托记录
     * @param status
     * @param listener
     */
    public static void getAdsList(int status,String tokenId,int page,int size, SimpleResponseListener<OtcAdsListResponse> listener){
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_PERSONAL_ENTRUST_LIST)
                .addParam("status",status)
                .addParam("tokenId",tokenId)
//                .addParam("beginTime",beginTime)
//                .addParam("endTime",endTime)
//                .addParam("side",side)
                .addParam("page",page)
                .addParam("size",size)
                .build();
        HttpUtils.getInstance().request(params,OtcAdsListResponse.class,listener);
    }

    /**
     * 发布广告
     * @param isBuy
     * @param tokenId
     * @param currencyId
     * @param isFloatingPrice
     * @param price
     * @param num
     * @param minAmount
     * @param maxAmount
     * @param remark
     * @param tradePwd
     * @param listener
     */
    public static void publishAds(boolean isBuy,String tokenId, String currencyId,boolean isFloatingPrice, String price, String num, String minAmount, String maxAmount, String remark,String tradePwd,SimpleResponseListener<OtcPublishAdResponse> listener) {
        PostParams params = BParamsBuilder.post()
                .url(OTCUrls.OTC_CREATE)
                .addParam("tokenId",tokenId)
                .addParam("currencyId",currencyId)
                .addParam("side",isBuy?0:1)
                .addParam("priceType",isFloatingPrice?1:0)
                .addParam("price",isFloatingPrice?"":price)
                .addParam("premium",isFloatingPrice?price:"")
                .addParam("quantity",num)
                .addParam("minAmount",minAmount)
                .addParam("maxAmount",maxAmount)
                .addParam("tradePwd",MD5Utils.encode(tradePwd))
                .addParam("remark",remark)
                .build();
        HttpUtils.getInstance().request(params,OtcPublishAdResponse.class,listener);
    }
}
